package getsmart.project.activity;

import java.util.ArrayList;

import getsmart.project.R;
import getsmart.project.database.DBProfil;
import getsmart.project.database.LogActivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.Toast;

public class ListProfil extends Activity implements View.OnClickListener{
	public int tempID = 1;
	public int getSize;
	String [] arrData;
	Button [] profName;
	int [] idProfil;
	DBProfil prof;
	EditText pertanyaan, kategori;
	LogActivity logAct;
	TableLayout tabel4data;// tabel for data
	public static int profileID = 0;
	private static void getProfileID(int id){
		ListProfil.profileID = id;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.list_profil);
		prof = new DBProfil(this);
		logAct = new LogActivity(this);
		tabel4data = (TableLayout) findViewById(R.id.tabel_data_profile_name);
		viewData();
	}
	protected void viewData() {
		// TODO Auto-generated method stub
		while (tabel4data.getChildCount() > 1) {
			tabel4data.removeViewAt(1);
		}
 
		ArrayList<ArrayList<Object>> data = prof.getProfile();//
		arrData = new String[data.size()];
		idProfil = new int[data.size()];
		for (int posisi = 0; posisi < data.size(); posisi++) {
			TableRow tabelBaris = new TableRow(this);
			ArrayList<Object> baris = data.get(posisi);
			getSize = data.size();
			idProfil[posisi] = Integer.parseInt(baris.get(0).toString());
			Button[] profName = new Button[data.size()]; 
			profName[posisi] = new Button(this);
			profName[posisi].setBackgroundResource(R.drawable.button_lainjuga);
			profName[posisi].setText(baris.get(1).toString());
			arrData[posisi] = baris.get(1).toString();
			profName[posisi].setOnClickListener(this);
			profName[posisi].setId(tempID);
			tabelBaris.addView(profName[posisi]);		
			tabel4data.addView(tabelBaris);
			tempID++;
		}
	}
	
	public void onClick(View v){
		Button b = (Button)v;
		for(int i = 1; i<getSize+1;i++){
			if(b.getId() == i){
				profileID = idProfil[i-1];
				logAct.addLog(profileID, "Membuka aplikasi");
				Intent in = new Intent(ListProfil.this,ChooseMenu.class);
				startActivity(in);
			}
		}
	}
}
